package com.gdqy.FCS.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.gdqy.FCS.entity.Weave;
import com.gdqy.FCS.service.WeaveService;




@Controller
@RequestMapping("weave")
public class WeaveController {

	@Autowired
	private WeaveService weaveService;
	
	/**
	 * 
	 *作者：张伟键
	 *方法描述：管理织法
	 * @return
	 */
	@RequestMapping("admin_weave")
	public ModelAndView admin_weave() {
		ModelAndView modelAndView = new ModelAndView();
		List<Weave> weaves = weaveService.selectAll();
		modelAndView.addObject("weaves", weaves);
		modelAndView.setViewName("admin/dictionaryWeave");
		return modelAndView;
	}
	
	@RequestMapping("add_weave")
	public @ResponseBody String add_weave(Weave weave) {
		String msg="fail";
		int data = weaveService.insert(weave);
		if(data>0) {
			msg="success";
		}
		return msg;
	}
	
	@RequestMapping("getWeaveByParent_code")
	public @ResponseBody List<Weave> getWeaveByParent_code(String parent_code){
		List<Weave> weaves = weaveService.selectByParent_code(parent_code);
		return weaves;
	}
	/*
	 * 
	 * 获取面料工艺列表
	 * 
	 * */
	@RequestMapping("getWeaveList")
	public ModelAndView getWeaveList() {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("fabic");
		
		List<Weave> list=weaveService.selectAll();
		modelAndView.addObject(list);
		
		return modelAndView;

	}

	/*
	 * 
	 * 通过id获取面料工艺详情
	 * 
	 * */
	@RequestMapping("getWeaveById")
	public ModelAndView getFabricById(String id) {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("index");
		
		Weave weave=weaveService.selectById(Integer.parseInt(id));
		modelAndView.addObject(weave); 
		
		return modelAndView;

	}
	


}
